package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC831 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public String maskPII(String S) {
            int atIndex = S.indexOf('@');
            if (atIndex >= 0) { // email
                return (S.substring(0, 1) + "*****" + S.substring(atIndex - 1)).toLowerCase();
            } else { // phone
                String digits = S.replaceAll("\\D+", "");
                String local = "***-***-" + digits.substring(digits.length() - 4);
                if (digits.length() == 10) return local;
                String ans = "+";
                for (int i = 0; i < digits.length() - 10; ++i)
                    ans += "*";
                return ans + "-" + local;
            }
        }
    }


    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC831 an = new LC831();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
